package cxy.highConcurrency;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

public class CompletableFutureDemo_3 {
	public static void main(String[] args) {

		CompletableFuture<String> f1 = CompletableFuture.supplyAsync(() -> {
			int t = 2;
			sleep(t, TimeUnit.SECONDS);
			return String.valueOf(t);
		});

		CompletableFuture<String> f2 = CompletableFuture.supplyAsync(() -> {
			int t = 3;
			sleep(t, TimeUnit.SECONDS);
			return String.valueOf(t);
		});

		CompletableFuture<String> f3 = f1.applyToEither(f2, s -> s);

		System.out.println(f3.join());
		
		
	}
	
	static void sleep(int t, TimeUnit u)  {
		try { 
			u.sleep(t); 
		}catch(InterruptedException e){
				
		}
	}
	
	
}
